/**
实现功能:按照单选按钮name值,分组的按钮组中实现单选按钮的选中和取消选中效果
*/

//author: 安仲炜

    ;(function($, window, document, undefined){
    var MyPlugin = function(obj){
        this.$object = obj,
        this.className = this.getClass(),
        this.elementName = this.getElementName()
        //this.options = $.extend({}, this.defaults, opt)
    }

    MyPlugin.prototype = {
        init: function() {
            if(this.$object.data('check') == '1'){
                $(':radio[name="'+ this.elementName +'"]').each(function(){
                    $(this).data('check','1');
                });
                this.$object.data('check','2');
                alert('选中');
            }
            else if(this.$object.data('check') == '2'){
                this.$object.data('check','1');
                this.$object.removeAttr('checked');
                alert('取消选中');
            }
        },
        getClass: function(){
            return this.$object.attr('class');
        },
        getElementName: function(){
            return this.$object.attr('name');
        },
        setDataAttr: function(){
            $('.'+this.className).data('check','1');
        }
    }
    
    $.fn.radioChecked = function(){
        return new MyPlugin(this);
    }
})(jQuery, window, document);